package com.itfreer.data.metadata;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.itfreer.data.metadata.entity.DataDictionaryEntity;
import com.itfreer.form.api.BaseRestService;
import com.itfreer.form.api.BaseService;
import com.itfreer.form.api.dictionary.DictionaryEntity;
import com.itfreer.utils.ResponseEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 字典
 */
@RestController
@RequestMapping("/dictionary")
@Api("默认字典")
public class RestDefaultDictionaryService extends BaseRestService<DataDictionaryEntity> {
	
	@Autowired(required = false)
	private DefaultDictionaryService service;
	
	@Override
	protected BaseService<DataDictionaryEntity> getService() {
		return getServiceEx();
	}
	
	protected DefaultDictionaryService getServiceEx() {
		return service;
	}
	
	@ApiOperation(value = "获取字典", notes = "根据字典名称，获取字典项")
	@ApiImplicitParams(value = { @ApiImplicitParam(name = "id", value = "字典名称", paramType = "path", required = true) })
	@PostMapping(value = "/getEntitys/{id:.+}", produces = "application/json")
	public ResponseEntity<List<DictionaryEntity>> getEntitysByID(@PathVariable("id") String dicName) {
		return new ResponseEntity<List<DictionaryEntity>>(getServiceEx().getEntitys(dicName));
	}
	
	/**
	 * 指量删除实体
	 * 
	 * @param guid
	 *            唯一值集
	 */
	@ApiOperation(value = "删除字典")
	@ApiImplicitParams(value = { 
			@ApiImplicitParam(name = "dn", value = "字典名称", paramType = "path", required = true),
			@ApiImplicitParam(name = "ids", value = "字典值", paramType = "path", required = true) })
	@DeleteMapping(value = "/deletesex/{dn:.+}/{ids:.+}", produces = "application/json")
	public void deletes(@PathVariable("dn") String dn, @PathVariable("ids") String guids) {
		getServiceEx().deletes(dn, guids);
	}
}